package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.utility.nullability.UnknownNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ShopController
 * @Package: com.sky.controller.admin
 * @Author: 金磊
 * @CreateDate: 2025/4/11 - 10:33
 * @Version: V1.0.0
 * @Description:
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺营业状态为:{}", status == 1 ? "营业中" : "打烊");
        redisTemplate.opsForValue().set(ShopStatusConstant.SHOP_STATUS, status);
        log.info("设置成功");
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(ShopStatusConstant.SHOP_STATUS);
        log.info("获取店铺营业状态为:{}", status == 1 ? "营业中" : "打烊");

        return Result.success(status);
    }

}
